package com.itheima.appserver.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.appserver.interceptor.UserThreadLocal;
import com.itheima.commons.model.mongo.Album;
import com.itheima.commons.model.mongo.Publish;
import com.itheima.dubbo.interfaces.AlbumApi;
import org.bson.types.ObjectId;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 个人相册业务类
 */
@Service
public class AlbumService {

    @Reference
    private AlbumApi albumApi;

    /**
     * 将新发布的圈子ID保存到自己的相册表中
     *
     * @param publishId
     */
    public void save(String publishId) {
        Album album = new Album();
        album.setId(ObjectId.get());
        album.setPublishId(new ObjectId(publishId));
        album.setCreated(System.currentTimeMillis());
        albumApi.saveAlbum(album, UserThreadLocal.getUserId());
    }

    /**
     * 分页查询自己的所有圈子动态
     *
     * @param page
     * @param pageSize
     * @param userId
     * @return
     */
    public List<Publish> findMovementsByUserId(Integer page, Integer pageSize, Long userId) {
        return albumApi.findMovementsByUserId(page, pageSize, userId);
    }

}
